/**
 * 用户相关接口
 * @authors 杨兴洲（of2502）
 * @date    2017/3/28 10:27
 * @version 1.0
 */
/// <reference path="./weixin-statistic-service.d.ts" />
import * as rp from "request-promise-native";
const HOST = 'https://api.weixin.qq.com';

export default class WeixinStatistic {
    /**
     * 获取用户增减数据
     * @param access_token
     * @param begin_date
     * @param end_date
     * @returns {Promise<UserSummary[]>}
     */
    static getUserSummary({access_token, begin_date, end_date}: userParams): Promise<UserSummary[]> {
        return rp({
            method: 'POST',
            uri: `${HOST}/datacube/getusersummary`,
            qs: {access_token},
            body: {begin_date, end_date},
            json: true
        })
            .then((data: any) => data.errcode ? Promise.reject(data) : data.list);
    }

    /**
     * 获取累计用户数据
     * @param access_token
     * @param begin_date
     * @param end_date
     * @returns {Promise<userCumulate[]>}
     */
    static getUserCumulate({access_token, begin_date, end_date}: userParams): Promise<userCumulate[]> {
        return rp({
            method: 'POST',
            uri: `${HOST}/datacube/getusercumulate`,
            qs: {access_token},
            body: {begin_date, end_date},
            json: true
        })
            .then((data: any) => data.errcode ? Promise.reject(data) : data.list);
    }

    /**
     * 获取消息发送概况数据
     * @param access_token
     * @param begin_date
     * @param end_date
     * @returns {Promise<msgCumulate[]>}
     */
    static getMsgData({access_token, begin_date, end_date}: userParams): Promise<msgCumulate[]> {
        return rp({
            method: 'POST',
            uri: `${HOST}/datacube/getupstreammsg`,
            qs: {access_token},
            body: {begin_date, end_date},
            json: true
        })
            .then((data: any) => data.errcode ? Promise.reject(data) : data.list);
    }

}
